<template>
    <div style="height:0.36rem">
        <div class="onlineBox flex flex-align-center">
            <p class="zg">总共人数：<span>{{total_num}}</span></p>
            <p class="zx flex-1">在线人数：<span>{{online_num}}</span></p>
           <div class="inputBox flex" v-show="isShow">
               <input type="text" placeholder="输入会员名称" v-model.trim="userName">
               <div class="sousBtn  flex flex-align-center flex-pack-center" @click="onSearchFun"><p>搜索</p></div>
           </div>
           <!-- 发送群消息 -->
            <div class="qfBtn  flex flex-align-center flex-pack-center" v-show="!isShow" @click="onSendMsgFun" v-if='$store.state.userInfo.superior != 0'>
                <p>发送群消息</p>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    props: {
        isShow: Boolean,
        default:false
    },
    data () {
        return {
            userName:'',
            online_num:0,
            total_num:0,
        }
    },
    watch: {
       userName(news,old){
           if(news == ''){
               let uid = this.$store.state.liststatus.parent_id;
               let login_status = this.$store.state.liststatus.login_status;
               this.getNetUserList(uid,news,login_status);
           }
       } 
    },
    mounted () {
        let _self = this;
        _self.postObtainUserOnlineNumber();
        window.setInterval(function(){
            _self.postObtainUserOnlineNumber();
        },300000);
    },
    methods: {
        onSearchFun(){ //搜索用户列表
            if(this.userName){
                let uid = this.$store.state.liststatus.parent_id;
                let login_status = this.$store.state.liststatus.login_status;
                this.getNetUserList(uid,this.userName,login_status);
            }
        },
        getNetUserList(uid,keyword,login_status){ //获取列表数据
            this.https('chat/postObtainSubordinateUserList',{uid:uid,keyword:keyword,login_status:login_status},'post')
            .then(data => {
                this.$store.commit('setMembershiplist',data.list);
            })
        },
        onSendMsgFun(){ //群发消息
            this.$emit('send','0');
        },
        postObtainUserOnlineNumber(){
            let uid = this.$store.state.userInfo.id;
            this.https('Chat/postObtainUserOnlineNumber',{uid:uid})
            .then(data => {
                let _self = this;
                this.online_num = data.online_num;
                this.total_num = data.total_num;
            })
        }
    }
}
</script>
<style lang="less" scoped>
@import url(../../../assets/css/chatroom/onlinenumber.less);
</style>


